const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime
}


// 检测是不是今天第一次获取该数据
function getDinnerList() {
  var dinnerlist;
  try {
    var dinnerlist = wx.getStorageSync('dinnerlist');
    if (!dinnerlist) {
      console.log("写死数据");
      dinnerlist = getApp().globalData.dinnerlist;
    } else {
      console.log("本地缓存");
    }
    console.log(dinnerlist);
  } catch (e) {
    console.log(e);
  }
  return dinnerlist;
}

function setDinnerList(dinnerlist) {
  try {
    wx.setStorageSync('dinnerlist', dinnerlist);
  } catch (e) {
    console.log("存储失败" + e);
  }
  console.log("存储成功");
}

module.exports.getDinnerList = getDinnerList
module.exports.setDinnerList = setDinnerList